package com.lvhx.java8;

import com.google.common.collect.Maps;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class GoogleGuavaTest {
    private Map<Integer,String> map = initMap();

    @Test
    public void test1(){
        //1.过滤key符合条件的数据
        Map<Integer, String> map1 = Maps.filterKeys(this.map, k -> k.intValue() == 1);
        System.out.println(map1);
        //2.过滤value符合条件的数据
        Map<Integer, String> map2 = Maps.filterValues(map, v -> v.equals("B"));
        System.out.println(map1);
        //3.k，v都筛选
        Map<Integer, String> map3 = Maps.filterEntries(this.map, m -> m.getKey().intValue() == 1 && m.getValue().equals("A"));
        System.out.println(map3);

    }

    public Map<Integer,String> initMap(){
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1,"A");
        map.put(2,"B");
        map.put(3,"C");
        return map;
    }
}
